package com.ms.member.controller;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Properties;

/**
 * 会员登录注册管理Controller
 * Created by macro on 2018/8/3.
 */
@RestController
@Api(tags = "UmsMemberController", description = "会员登录注册管理")
@RequestMapping("/sso")
@Slf4j
public class UmsMemberController {


    @Value("${config.title:test}" )
    private  String title ;
    @Value("${config.mail:test}" )
    private  String mail ;

    /**
     * 获取广告类型--开屏广告
     */
    @ApiOperation(value = "获取广告类型", notes = "获取广告类型")
    @GetMapping("/advertiseType")
    public String  advertiseType() {
        // 使用nacos客户端远程获取服务上配置信息
//         nacos address
        String serverAddr = "192.168.1.203:8848";
        // nacos information
        String dataID = "nacos-demo-dev.yaml";
        String group = "DEFAULT_GROUP";
        Properties properties = new Properties();
        properties.put("serverAddr",serverAddr);
        properties.put("namespace","06d881b0-eefd-466f-945c-04d8ed0ebcb3");
        ConfigService configService = null;
        String config="";
        try {
            configService = NacosFactory.createConfigService(properties);
             config = configService.getConfig(dataID, group, 5000);
        } catch (NacosException e) {
            e.printStackTrace();
        }


        return "hello world"+config;
    }


}
